﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace temperatureGui
{
    public static class LiteDb
    {
        static SQLiteConnection dbConnection;
        static LiteDb()
        {
            dbConnection = new SQLiteConnection("Data Source=monitor.db;Version=3;");
            dbConnection.Open();
            createTable();
        }
        static void createTable()
        {
            string sql = "create table if not exists m_temperature (device varchar(20), collect_time varchar(20) ,degree int)";
            SQLiteCommand command = new SQLiteCommand(sql, dbConnection);
            command.ExecuteNonQuery();
        }
        public static void InsertMsg(TemperatureMsg msg)
        {
            string sql = "insert into m_temperature values(@p1,@p2,@p3)";
            SQLiteCommand command = new SQLiteCommand(sql, dbConnection);
            command.Parameters.Add(new SQLiteParameter("@p1",msg.Device));
            command.Parameters.Add(new SQLiteParameter("@p2", msg.Time));
            command.Parameters.Add(new SQLiteParameter("@p3", msg.Degree));
            command.ExecuteNonQuery();
        }
    }
}
